package com.yqg.protection.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.protection.common.Result;
import com.yqg.protection.entity.Sdf300HistoryData;
import com.yqg.protection.mapper.Sdf300HistoryDataMapper;
import com.yqg.protection.service.ISdf300HistoryDataService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * Sdf300HistoryDataController 前端控制器
 * @author zxf
 * @since 2025-08-08
 */
@RestController
@RequestMapping("/sdf300-history-data")
public class Sdf300HistoryDataController {

    @Resource
    private ISdf300HistoryDataService sdf300HistoryDataService;

    @Resource
    private Sdf300HistoryDataMapper sdf300HistoryDataMapper;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody Sdf300HistoryData sdf300HistoryData) {
        return Result.success(sdf300HistoryDataService.saveOrUpdate(sdf300HistoryData));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        return Result.success(sdf300HistoryDataService.removeById(id));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<Sdf300HistoryData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
       List<Sdf300HistoryData> list=  sdf300HistoryDataService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(sdf300HistoryDataService.getById(id));
    }
    /**
    *  分页查询
    */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           Long equipmentInputStoreId,
                           String startTime,
                           String endTime) {
        pageNum = pageNum * pageSize - pageSize;
        List<Sdf300HistoryData> sdf300HistoryDataList = sdf300HistoryDataMapper.findPage(pageNum, pageSize, equipmentInputStoreId, startTime, endTime);
        Long count = sdf300HistoryDataMapper.findPageCount(equipmentInputStoreId, startTime, endTime);
        HashMap<String, Object> map = new HashMap<>();
        map.put("record", sdf300HistoryDataList);
        map.put("total", count);
        return Result.success(map);
    }

    /**
     *  根据id查询
     */
    @GetMapping("/getInfo")
    public Result getInfo(@RequestParam Long equipmentInputStoreId,
                          @RequestParam String warnTime) {
        LambdaQueryWrapper<Sdf300HistoryData> sdf300HistoryDataQueryWrapper = new LambdaQueryWrapper<>();
        sdf300HistoryDataQueryWrapper.eq(Sdf300HistoryData::getEquipmentInputStoreId, equipmentInputStoreId);
        sdf300HistoryDataQueryWrapper.eq(Sdf300HistoryData::getSendTime, warnTime);
        return Result.success(sdf300HistoryDataService.getOne(sdf300HistoryDataQueryWrapper));
    }

}

